#ifndef _SCENE_H_
#define _SCENE_H_

#include <stdio.h>
#include "../../ExEngine/common/hashtable.hpp"
#include "../../ExEngine/common/arraylist.hpp"

#include "../../ExEngine/physics/characteractor.h"
#include "../../ExEngine/render/interface_types.h"
#include "../../ExEngine/sound/dsound.h"
#include "../../ExEngine/math/vector.h"
#include "../../ExEngine/math/bezier.h"

HRESULT LoadDemo(); 
HRESULT ShutdownDemo(); 
HRESULT UpdateDemo(const float dt); 

class CPlayer : public CObject
{
public:
	enum Driver { HUMAN = 0,
		BEZIER,
		POINT,
		DIRECTION};

private:

	Vector3f m_LastPosition;
	Vector3f m_PointController;
	Bezier m_BezierController;

	Driver m_Driver;
	bool m_IsRunning;
	float m_Angle;
	float m_SteerUnarity;
	Vector3f m_CameraAnchor;
	Vector3f m_CameraTarget;
	Vector3f m_Forward;
	float m_Speed;
	CCharacterActor::CharacterState m_LastPhysicsState;
	struct jumpFilp
	{
		float angle;
		bool isDone;

		jumpFilp() : angle(0), isDone(true)
		{}
	}m_jumpFlip;

	inline void RecoverDirection(const Vector3f& relativeTo);
	inline float GetMoveSpeed();
	CCharacterActor* GetPhysicsCharacter();
	void UpdateTransform();

	void UpdateHumanDriver(const float dt);
	void UpdatePointDriver(const float dt);
	void UpdateDirectionDriver(const float dt);
	void UpdateBezierDriver(const float dt);

	float GetInputSteer();
	float GetWalkMagnitude();

public:
	
	typedef  void (CPlayer::*EvtHandler)(void);
	void CallEvent(EvtHandler memFn)
	{
		(this->*(memFn))();
	}
	void BeginJump();
	void OnLanding();

	void BeginRunning();
	void Running();
	void EndRunning();
	void Idle();

	void SetDirectionDriver(const Vector3f& target);
	void SetPointDriver(const Vector3f& target);
	void SetBezierDriver(const Bezier& target);
	void SetHumanDriver();
	Driver GetDriver();
	
	Vector3f CameraAnchor();
	Vector3f CameraTarget();

	CPlayer();
	HRESULT Create();
	HRESULT Release();

	void setPosition(const Vector3f &position); 

	void Update(const float dt);
	void Draw(void); 
};

#endif